var livelyIndex;
var crraeStatus = 5;

$(function() {
	livelyIndex = GetParpam("livelyIndex");
	if(livelyIndex){
		dataSave("livelyIndex", livelyIndex);
	}

	loaded();
});

function loaded() {
	var data = "&crraeUuid="+dataGet("livelyIndex")+"&userUuid="+dataGet("userUuid");
	var url = urlfile + "coreRideActive/views";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + data);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				$('#addLivelyDesc').html('<img src="'+urlfile +'coreAttachment/image/get/' + data.data.list[0].cratmUuid+'" class="img_Lively_desc"/>');
				crraeStatus = data.data.crraeStatus;
				var statusName = "未报名";
				if(crraeStatus == 1) {
					statusName = "已报名";
				}
				if(crraeStatus == 2) {
					statusName = "已付款";
				}
				if(crraeStatus == 3) {
					statusName = "已取消";
				}
				if(crraeStatus == 4) {
					statusName = "已完成";
				}
				$('#addLivelyDescCount').html("累计" + data.data.crraeCount + "人报名  " + statusName);
				$('#addLivelyDescTitle').html(data.data.crraeTitle );
				$('#addLivelyDescContent').html(data.data.crraeContent);
				$('#addLivelyDesc_price').html("报名费：￥" + data.data.crraeValue);
			}
		}
	);
}

function toAddLivePay() {
	if(crraeStatus == 1 || crraeStatus == 2 || crraeStatus == 4) {
		alert('已在报名阶段，不需要重复报名！');
		return;
	}

	validSession();
	
	if(!dataGet('isLogined')){
		dataSave("openId", "");
		dataSave("loginType", "addlively");
		nextView("../../../page/OAuthGetCodeLogin.html");
		return;
	}
	
	var r = confirm("确定报名此活动");
    if (r==false) {
        return;
    }

    layer.open({type: 2});

	var data = "&crraeUuid="+dataGet("livelyIndex")+"&crrrdUser="+dataGet("userUuid");
	var url = urlfile + "coreRideRecord//add/coreRideRecord";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + data);
			layer.closeAll();
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
				layer.closeAll();
				loaded();
			}else{
				alert("报名成功,我们将尽快与您联系");
				layer.closeAll();
				loaded();
			}
		}
	);
}